//
// Created by 成飞 on 2024/1/4.
//

#include "bootstrap.h"
#include "db/server.h"
#include <iostream>

using namespace std;

void start(){
    auto *sys = new db::Server;

    string key,val;
    key = "1"; val = "123456789";
    sys->put(key, val);
    key ="2"; val = "23456789";
    sys->put(key, val);
    key ="3"; val = "3456789";
    sys->put(key, val);
    key ="4"; val = "45678999";
    sys->put(key, val);
    key ="5"; val = "56789";
    sys->put(key, val);
    key ="6"; val = "6789";
    sys->put(key, val);
    key ="7"; val = "aaaaa";
    sys->put(key, val);

    cout << "query 1" << endl;
    key = "1";
    cout << sys->query(key) << endl;
    cout << "query 3" << endl;
    key = "3";
    cout << sys->query(key) << endl;



    key = "8"; val = "x12345678999999";
    sys->put(key, val);
    key = "9"; val = "x23456789xxxggfs";
    sys->put(key, val);
    key = "10"; val = "x3456789fasfasfdafadfdsfdafafdsfadasfasfafasfas";
    sys->put(key, val);



    key = "1"; val = "x56789fdafaasfa";
    sys->put(key, val);
    key = "3"; val = "x456789fasdfasfadsddfafa";
    sys->put(key, val);
    key = "8"; val = "xaaaaafdafa";
    sys->put(key, val);
    key = "13"; val = "x6789jjjfdafas";
    sys->put(key, val);

    cout << "query 1" << endl;
    key = "1";
    auto q1 = sys->query(key);
    cout << "|" << q1 << "|" << endl;

    cout << "query 3" << endl;
    key = "3";
    auto q3 = sys->query(key);
    cout << "|" << q3 << "|" << endl;

    cout << "query 7" << endl;
    key = "7";
    auto q7 = sys->query(key);
    cout << "|" << q7 << "|" << endl;

    cout << "query 13" << endl;
    key = "13";
    auto q13 = sys->query(key);
    cout << "|" << q13 << "|" << endl;

    cout << "----------------------------" << endl;
    cout << "range query" << endl;
    string key1 = "0", key2 = "9";
    auto rq1_8 = sys->range_query(key1, key2, 8);
    for (auto &it: rq1_8) {
        cout << "|"<< it.first <<" " << it.second << "|"<< endl;
    }

    std::this_thread::sleep_for(std::chrono::seconds(3));

    cout << "----------------------------" << endl;
    cout << "range query" << endl;
    rq1_8 = sys->range_query(key1, key2, 3);
    for (auto &it: rq1_8) {
        cout << "|"<< it.first <<" " << it.second << "|"<< endl;
    }

    this_thread::sleep_for(chrono::seconds(3));

    delete sys;

    /*sys->put("1", "123456789");
    sys->put("2", "23456789");
    sys->put("3", "3456789");
    sys->put("4", "45678999");
    sys->put("5", "56789");
    sys->put("6", "6789");
    sys->put("7", "aaaaa");

    cout << "query 1" << endl;
    cout << sys->query("1") << endl;

    cout << "query 3" << endl;
    auto q3 = sys->query("3");
    cout << "|" << q3 << "|" << endl;

    cout << "query 7" << endl;
    auto q7 = sys->query("7");
    cout << "|" << q7 << "|" << endl;

    cout << "query 13" << endl;
    auto q13 = sys->query("13");
    cout << "|" << q13 << "|" << endl;

    cout << "----------------------------" << endl;
    cout << "range query" << endl;
    auto rq1_8 = sys->range_query("1", "9");
    for (auto &it: rq1_8) {
        cout << "|"<< it.first <<" " << it.second << "|"<< endl;
    }

    std::this_thread::sleep_for(std::chrono::seconds(3));

    cout << "----------------------------" << endl;
    cout << "range query" << endl;
    rq1_8 = sys->range_query("1", "9");
    for (auto &it: rq1_8) {
        cout << "|"<< it.first <<" " << it.second << "|"<< endl;
    }

    this_thread::sleep_for(chrono::seconds(5));

    delete sys;*/
}

void start2(){
    auto *sys = new db::Server;

    cout << "range query" << endl;
    string key1 = "0", key2 = "9";
    auto rq1_8 = sys->range_query(key1, key2, 10);
    for (auto &it: rq1_8) {
        cout << "|"<< it.first <<" " << it.second << "|"<< endl;
    }
    delete sys;
}